//
//  MainViewController.swift
//  weibo
//
//  Created by 叶子韬韬 on 2017/4/19.
//  Copyright © 2017年 叶子韬韬. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    // MARK:- #注释> 懒加载
    internal lazy var imageNames = ["tabbar_home_highlighted","tabbar_message_center_highlighted","","tabbar_discover_highlighted","tabbar_profile_highlighted"]
    
//    internal lazy var composeBtn:UIButton = UIButton.createButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
    
    internal lazy var composeBtn:UIButton = UIButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupComposeBtn()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
//        setupTabbarItems()
    }

}

extension MainViewController{
    
    internal func setupComposeBtn(){
        
        // 1.将composeBtn添加到tabbar中
        tabBar.addSubview(composeBtn)
        
        //设置位置
        composeBtn.center.x = tabBar.center.x
        composeBtn.center.y = tabBar.bounds.size.height*0.5
        
       composeBtn.addTarget(self, action: #selector(MainViewController.composeBtnClick), for: .touchUpInside)
        
    }
    /*
     internal func setupTabbarItems(){
        // MARK:- #注释>遍历所有item
        for i in 0..<tabBar.items!.count{
            //获取item
            let item = tabBar.items![i]
            
            if i==2 {
                item.isEnabled = false
            }
            //设置选中图片
            item.selectedImage = UIImage(named: imageNames[i])
            
        }

    }
 */
    
}
//// MARK:- #注释>事件监听
extension MainViewController{
    internal func composeBtnClick(){
//        print("222")
        let composeVC = ComposeViewController ()
        
        //包装导航控制器
        let nav = UINavigationController.init(rootViewController: composeVC)
        
        present(nav, animated: true, completion: nil)
        
        
        
        
    }
}
